new test program for the tree.
authorJonathan Blandford <jrb@redhat.com>
Thu, 18 Oct 2001 18:58:47 +0000 (18:58 +0000)
committerJonathan Blandford <jrb@src.gnome.org>
Thu, 18 Oct 2001 18:58:47 +0000 (18:58 +0000)
Thu Oct 18 14:58:14 2001  Jonathan Blandford  <jrb@redhat.com>

* tests/testtreeflow.c: new test program for the tree.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
tests/Makefile.am
tests/testtreeflow.c [new file with mode: 0644]

index cf970ad3dd956de1855c9bd6e2e3b55d8701d476..82a1ed5b5988e78f3497b957eedbeffec2b12876 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Thu Oct 18 14:58:14 2001  Jonathan Blandford  <jrb@redhat.com>
+
+       * tests/testtreeflow.c: new test program for the tree.
+
 Thu Oct 18 14:22:10 2001  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtktreestore.c (gtk_tree_store_remove): fix small bug
index cf970ad3dd956de1855c9bd6e2e3b55d8701d476..82a1ed5b5988e78f3497b957eedbeffec2b12876 100644 (file)
@@ -1,3 +1,7 @@
+Thu Oct 18 14:58:14 2001  Jonathan Blandford  <jrb@redhat.com>
+
+       * tests/testtreeflow.c: new test program for the tree.
+
 Thu Oct 18 14:22:10 2001  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtktreestore.c (gtk_tree_store_remove): fix small bug
index cf970ad3dd956de1855c9bd6e2e3b55d8701d476..82a1ed5b5988e78f3497b957eedbeffec2b12876 100644 (file)
@@ -1,3 +1,7 @@
+Thu Oct 18 14:58:14 2001  Jonathan Blandford  <jrb@redhat.com>
+
+       * tests/testtreeflow.c: new test program for the tree.
+
 Thu Oct 18 14:22:10 2001  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtktreestore.c (gtk_tree_store_remove): fix small bug
index cf970ad3dd956de1855c9bd6e2e3b55d8701d476..82a1ed5b5988e78f3497b957eedbeffec2b12876 100644 (file)
@@ -1,3 +1,7 @@
+Thu Oct 18 14:58:14 2001  Jonathan Blandford  <jrb@redhat.com>
+
+       * tests/testtreeflow.c: new test program for the tree.
+
 Thu Oct 18 14:22:10 2001  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtktreestore.c (gtk_tree_store_remove): fix small bug
index cf970ad3dd956de1855c9bd6e2e3b55d8701d476..82a1ed5b5988e78f3497b957eedbeffec2b12876 100644 (file)
@@ -1,3 +1,7 @@
+Thu Oct 18 14:58:14 2001  Jonathan Blandford  <jrb@redhat.com>
+
+       * tests/testtreeflow.c: new test program for the tree.
+
 Thu Oct 18 14:22:10 2001  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtktreestore.c (gtk_tree_store_remove): fix small bug
index cf970ad3dd956de1855c9bd6e2e3b55d8701d476..82a1ed5b5988e78f3497b957eedbeffec2b12876 100644 (file)
@@ -1,3 +1,7 @@
+Thu Oct 18 14:58:14 2001  Jonathan Blandford  <jrb@redhat.com>
+
+       * tests/testtreeflow.c: new test program for the tree.
+
 Thu Oct 18 14:22:10 2001  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtktreestore.c (gtk_tree_store_remove): fix small bug
index cf970ad3dd956de1855c9bd6e2e3b55d8701d476..82a1ed5b5988e78f3497b957eedbeffec2b12876 100644 (file)
@@ -1,3 +1,7 @@
+Thu Oct 18 14:58:14 2001  Jonathan Blandford  <jrb@redhat.com>
+
+       * tests/testtreeflow.c: new test program for the tree.
+
 Thu Oct 18 14:22:10 2001  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtktreestore.c (gtk_tree_store_remove): fix small bug
index 44512c0616bfc4718c252bee8c838f992b65ec63..a5a9853ba871c1f38c4481443adb07cc2aa92832 100644 (file)
@@ -38,6 +38,7 @@ noinst_PROGRAMS =             \
        testtreeedit            \
        testtreeview            \
        testtreefocus           \
+       testtreeflow            \
        testtreecolumns         \
        testtreesort            \
        treestoretest
@@ -56,6 +57,7 @@ testtextbuffer_DEPENDENCIES = $(TEST_DEPS)
 testtreeedit_DEPENDENCIS = $(DEPS)
 testtreeview_DEPENDENCIES = $(DEPS)
 testtreefocus_DEPENDENCIES = $(DEPS)
+testtreeflow_DEPENDENCIES = $(DEPS)
 testtreecolumns_DEPENDENCIES = $(DEPS)
 testtreesort_DEPENDENCIES = $(DEPS)
 treestoretest_DEPENDENCIES = $(TEST_DEPS)
@@ -73,6 +75,7 @@ testtextbuffer_LDADD = $(LDADDS)
 testtreeedit_LDADD = $(LDADDS)
 testtreeview_LDADD = $(LDADDS)
 testtreefocus_LDADD = $(LDADDS)
+testtreeflow_LDADD = $(LDADDS)
 testtreecolumns_LDADD = $(LDADDS)
 testtreesort_LDADD = $(LDADDS)
 testtext_LDADD = $(LDADDS)
diff --git a/tests/testtreeflow.c b/tests/testtreeflow.c
new file mode 100644 (file)
index 0000000..5625e46
--- /dev/null
@@ -0,0 +1,144 @@
+#include <gtk/gtk.h>
+
+GtkTreeModel *model = NULL;
+GRand *rand = NULL;
+
+enum
+{
+  TEXT_COLUMN,
+  NUM_COLUMNS
+};
+
+static char *words[] =
+{
+  "Boom",
+  "Borp",
+  "Multiline\ntext",
+  "Bingo",
+  "Veni\nVedi\nVici",
+  NULL
+};
+
+
+#define NUM_WORDS 5
+#define NUM_ROWS 100
+
+
+static void
+initialize_model (void)
+{
+  gint i;
+  GtkTreeIter iter;
+
+  model = (GtkTreeModel *) gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING);
+  rand = g_rand_new ();
+  for (i = 0; i < NUM_ROWS; i++)
+    {
+      gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+      gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+                         TEXT_COLUMN, words[g_rand_int_range (rand, 0, NUM_WORDS)],
+                         -1);
+    }
+}
+
+static void
+futz_row (void)
+{
+  gint i;
+  GtkTreePath *path;
+  GtkTreeIter iter;
+  GtkTreeIter iter2;
+
+  i = g_rand_int_range (rand, 0,
+                       gtk_tree_model_iter_n_children (model, NULL));
+  path = gtk_tree_path_new ();
+  gtk_tree_path_append_index (path, i);
+  gtk_tree_model_get_iter (model, &iter, path);
+  gtk_tree_path_free (path);
+
+  switch (g_rand_int_range (rand, 0, 3))
+    {
+    case 0:
+      /* insert */
+      gtk_list_store_insert_after (GTK_LIST_STORE (model),
+                                  &iter2, &iter);
+      gtk_list_store_set (GTK_LIST_STORE (model), &iter2,
+                         TEXT_COLUMN, words[g_rand_int_range (rand, 0, NUM_WORDS)],
+                         -1);
+      break;
+    case 1:
+      /* delete */
+      if (gtk_tree_model_iter_n_children (model, NULL) == 0)
+       return;
+      gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+      break;
+    case 2:
+      /* modify */
+      if (gtk_tree_model_iter_n_children (model, NULL) == 0)
+       return;
+      gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+                         TEXT_COLUMN, words[g_rand_int_range (rand, 0, NUM_WORDS)],
+                         -1);
+      break;
+    }
+}
+
+static gboolean
+futz (void)
+{
+  gint i;
+
+  for (i = 0; i < 15; i++)
+    futz_row ();
+  g_print ("Number of rows: %d\n", gtk_tree_model_iter_n_children (model, NULL));
+  return TRUE;
+}
+
+int
+main (int argc, char *argv[])
+{
+  GtkWidget *window;
+  GtkWidget *vbox;
+  GtkWidget *scrolled_window;
+  GtkWidget *tree_view;
+  GtkWidget *hbox;
+  GtkWidget *button;
+
+  gtk_init (&argc, &argv);
+
+  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  gtk_window_set_title (GTK_WINDOW (window), "Reflow test");
+  gtk_signal_connect (GTK_OBJECT (window), "destroy", gtk_main_quit, NULL);
+  vbox = gtk_vbox_new (FALSE, 8);
+  gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
+  gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("Incremental Reflow Test"), FALSE, FALSE, 0);
+  gtk_container_add (GTK_CONTAINER (window), vbox);
+  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
+                                 GTK_POLICY_AUTOMATIC,
+                                 GTK_POLICY_AUTOMATIC);
+  gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
+  
+  initialize_model ();
+  tree_view = gtk_tree_view_new_with_model (model);
+  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
+  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
+                                              -1,
+                                              NULL,
+                                              gtk_cell_renderer_text_new (),
+                                              "text", TEXT_COLUMN,
+                                              NULL);
+  gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
+  hbox = gtk_hbox_new (FALSE, FALSE);
+  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+  button = gtk_button_new_with_mnemonic ("<b>_Futz!!</b>");
+  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+  gtk_label_set_use_markup (GTK_LABEL (GTK_BIN (button)->child), TRUE);
+  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (futz), NULL);
+  g_signal_connect (G_OBJECT (button), "realize", G_CALLBACK (gtk_widget_grab_focus), NULL);
+  gtk_window_set_default_size (GTK_WINDOW (window), 300, 400);
+  gtk_widget_show_all (window);
+  g_timeout_add (1000, futz, NULL);
+  gtk_main ();
+  return 0;
+}